package com.elink.enginerring.library;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.util.Map;

import javax.ws.rs.DefaultValue;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.elink.enginerring.category.service.ICategoryService;
import com.elink.enginerring.common.ErrorType;
import com.elink.enginerring.datasource.DataSourceContextHolder;
import com.elink.enginerring.datasource.DataSourceType;
import com.elink.enginerring.util.JSONUtil;

@Controller
@RequestMapping("view/thesis/category")
@Api(value="论文分类接口")
public class LibCategoryController {
	@Autowired
	private ICategoryService categoryService;

	/**
	 * 获取论文一级分类
	 * @return
	 */
	@RequestMapping(value = "/getTopCategory", method = RequestMethod.GET)
	@ApiOperation(value = "获取论文一级分类", httpMethod = "GET",  notes = "获取论文一级分类")
	@ResponseBody
	public Map<String, Object> getTopCategory() {
		DataSourceContextHolder.setDbType(DataSourceType.DBLIBRARY);
		System.out.println("选择的数据库" + DataSourceContextHolder.getDbType());
		return JSONUtil.getJSON(ErrorType.SUCCESS,categoryService.getTopCategoryOfLibrary());
	}

	/**
	 * 获取论文二级分类
	 * @param tcId
	 * @return
	 */
	@RequestMapping(value = "/getSecondaryCategory", method = RequestMethod.GET)
	@ApiOperation(value = "获取论文二级分类", httpMethod = "GET",  notes = "根据一级分类主键获取该一级分类下的二级分类")
	@ResponseBody
	public Map<String, Object> getSecondaryCategory(
			@RequestParam("tcId") int tcId) {
		DataSourceContextHolder.setDbType(DataSourceType.DBLIBRARY);
		System.out.println("选择的数据库" + DataSourceContextHolder.getDbType());
		return JSONUtil.getJSON(ErrorType.SUCCESS,categoryService.getSecondaryCategory(tcId));
	}
	
	/**
	 * 获取详情分类接口
	 * @param scId
	 * @return
	 */
	@RequestMapping(value = "/getDetailCategory", method = RequestMethod.GET)
	@ApiOperation(value = "获取论文详情分类", httpMethod = "GET",  notes = "获取论文详情分类")
	@ResponseBody
	public Map<String, Object> getDetailCategory(
			@RequestParam("scId") int scId,
			@RequestParam(value="dcTypeId",required=false)@DefaultValue("0") int dcTypeId) {
		
		DataSourceContextHolder.setDbType(DataSourceType.DBLIBRARY);
		System.out.println("选择的数据库" + DataSourceContextHolder.getDbType());
		return JSONUtil.getJSON(ErrorType.SUCCESS,categoryService.getDetailCategory(scId,dcTypeId));
	}
}
